package com.longxi.tianjintianbao.ui.adapter.multitype.contact;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectContactDetailListener;
import com.longxi.tianjintianbao.model.contact.ContactDetail;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class ContactListViewBinder extends ItemViewBinder<ContactDetail, ContactListViewBinder.ViewHolder> {

    SelectContactDetailListener listener;
    public ContactListViewBinder(SelectContactDetailListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_contact_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ContactDetail contactDetail) {
        holder.mTvContactName.setText(contactDetail.getPersonnelname());
        holder.mIvContactHead.setImageResource(R.mipmap.ic_l);
        holder.mRlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSuccess(contactDetail);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout mRlBtn;
        View mViewLine;
        ImageView mIvContactHead;
        TextView mTvContactName;
        RecyclerView mRvContent;
        ViewHolder(View itemView) {
            super(itemView);
            mRlBtn = itemView.findViewById(R.id.rlBtn);
            mViewLine = itemView.findViewById(R.id.viewLine);
            mIvContactHead = itemView.findViewById(R.id.ivContactHead);
            mTvContactName = itemView.findViewById(R.id.tvContactName);
            mRvContent = itemView.findViewById(R.id.rvContent);
        }
    }
}
